<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <!--搜索-->
      <div class="panel-container">
        <SearchUiNew ref="SearchUiNew" :searchFormArr="searchFormArr" @searchParma="searchParma"></SearchUiNew>
      </div>
      <!--数据信息-->
      <div class="panel-container no-margin">
        <el-table stripe :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="ID" prop="id" width="240"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="采集时间" prop="created_time"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="信息标题(原始)" prop="title" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="详细内容(原始)" prop="desc" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="联系电话" prop="user_phone"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="来源" prop="source"></af-table-column>
          <af-table-column align="center" fixed="right" header-align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button type="text" @click="handleApply(scope)">申领</el-button>
            </template>
          </af-table-column>
        </el-table>
        <el-pagination
          small
          background
          :current-page="pageNumber"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pageTotal"
          @current-change="currentChangeHandle"
          @size-change="sizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
          style="margin-top: 20px; text-align: right"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { apiAssetWaitAcceptList, apiApplyUserOneAccept } from '@/api/assetsPublic'
import {} from '@/utils'

export default {
  name: 'DialogAILog',
  props: {
    time: Object,
  },
  components: {},
  data() {
    return {
      searchFormArr: [
        {
          fieldName: '来源:',
          type: 'input',
          field: 'source',
          placeholder: '请输入来源',
        },
        {
          fieldName: '信息标题:',
          type: 'input',
          field: 'title',
          placeholder: '请输入信息标题',
        },
        {
          fieldName: '联系电话:',
          type: 'input',
          field: 'user_phone',
          placeholder: '请输入联系电话',
        },
      ],
      searchParams: {
        source: '',
        title: '',
        user_phone: '',
      },
      dataList: [],
      pageNumber: 1,
      pageSize: 10,
      pageTotal: 0,
      dataListLoading: false,
    }
  },
  activated() {
    this.$refs.table.doLayout()
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      const info = Object.assign({ pageNumber: this.pageNumber, pageSize: this.pageSize }, this.searchParams)
      apiAssetWaitAcceptList(info)
        .then((res) => {
          const { data, total } = res
          this.dataList = data
          this.pageTotal = total
          this.dataListLoading = false
          this.$refs.table.doLayout()
        })
        .catch((e) => {
          this.dataList = []
          this.pageTotal = 0
          this.dataListLoading = false
        })
    },
    // 列表查询
    searchParma(e) {
      // console.log(e)
      this.searchFormArr.forEach((item) => {
        if (e[item.field]) {
          this.searchParams[item.field] = e[item.field]
        } else {
          this.searchParams[item.field] = ''
        }
      })
      this.pageNumber = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageNumber = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNumber = val
      this.getDataList()
    },
    // 申领
    handleApply(scope) {
      apiApplyUserOneAccept({ id: scope.row.id }).then((res) => {
        this.$message({
          message: '申领成功',
          type: 'success',
        })
        this.getDataList()
      })
    },
  },
}
</script>

<style scoped lang="scss"></style>
